<template>
	<view class="content">
		<HM-dragSorts ref="dragSorts" :list="list" :autoScroll="true" :feedbackGenerator="true"
			:listHeight="winInnerHeight" :rowHeight="55" type="1" @change="change" @confirm="confirm"
			@onclick="onclick"></HM-dragSorts>
			<view class="posibottom mainpadding" style="padding-bottom: 0;">
				<view class="submitbtn" @click="submit">保存排序</view>
			</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				listid:"",
				winInnerHeight: 0,
			}
		},
		onLoad(options) {
			this.listid = options.id
			this.getCateList()
			this.winInnerHeight = window.outerHeight - 120;
		},
		methods: {
			submit(){
				uni.showLoading({
					mask:true,
					title:"請稍後"
				})
				let arr = []
				this.changeList.forEach((item,index)=>{
					arr.push({
						id:item.id,
						weigh:index
					})
				})
				this.http.request('/api/shop/updateCategoryWeigh', 'POST', {
					shop_id: uni.getStorageSync("shop_id"), //当前店鋪id
					data:arr
				}).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						uni.navigateBack(1)
					}
				})
			},
			getCateList() { //分类列表
				let _this = this
				uni.showLoading({
					mask: true,
					title: "請稍後"
				})
				this.http.request('/api/shop/listClass', 'POST', {
					shop_id: uni.getStorageSync("shop_id"), //当前店鋪id
					id: this.listid
				}).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						this.list = res.data
						this.changeList = res.data
					}
				})
			},
			onclick(e) {
				// console.log('=== onclick start ===');
				// console.log("被点击行: " + JSON.stringify(e.value));
				// console.log("被点击下标: " + JSON.stringify(e.index));
				// console.log('=== onclick end ===');
			},
			change(e) {
				// console.log('=== change start ===');
				// console.log("被拖动行: " + JSON.stringify(e.moveRow));
				// console.log('原始下标：', e.index);
				// console.log('移动到：', e.moveTo);
				// console.log('=== change end ===');
			},
			confirm(e) {
				this.changeList = e.list
				// console.log('=== confirm start ===');
				// console.log("被拖动行: " + JSON.stringify(e.moveRow));
				// console.log('原始下标：', e.index);
				// console.log('移动到：', e.moveTo);
				// console.log('=== confirm end ===');
			}
		}
	}
</script>

<style scoped>
	page{
		background-color: #fff;
	}
</style>